#!/usr/bin/env python
#  -*- coding: utf-8 -*-
__author__ = 'yinq'

product_list = [
    ('Iphone', 5800),
    ('MAC PRO', 12000),
    ('Bike', 800),
    ('Pen', 500),
    ('Python book', 50),
    ('Tea', 550),
    ('Coffee', 55),
]

shopping_list = []
salary = input("Please input your salary:")
if salary.isdigit():
    salary = int(salary)
    while True:
        for index, item in enumerate(product_list):
            print(index, item)

        choice_num = input("选择要买嘛？>>>:")
        if choice_num.isdigit():
            choice_num = int(choice_num)
            if choice_num < len(product_list) and choice_num >= 0:
                p_item = product_list[choice_num]
                if salary >= p_item[1]:
                    shopping_list.append(p_item)
                    salary -= p_item[1]
                    print("你已将商品 %s 添加到购物车，还剩 \033[31;1m%s\033[0m" % (p_item, salary))
                else:
                    print("钱不够啦！！还剩%s", salary)
            else:
                print("product code [%s] is not exist!" % choice_num)
        elif choice_num == 'q':
            print("-----product list----")
            for p in shopping_list:
                print(p)
            exit()
        else:
            print("请输入正确的商品编号！！")
else:
    print("请输入正确的工资！！")
